package com.sg.service.biz.framework.nb;

import com.sg.dto.biz.framework.common.AddDeptPositionDto;
import com.sg.dto.biz.framework.req.CheckRemovalObjsReqDto;
import com.sg.dto.biz.framework.req.ImplementClassDeptPositionAddFileReqDto;
import com.sg.dto.biz.framework.res.CheckRemovalObjsRespDto;
import com.sg.dto.biz.framework.res.ImplementClassDeptPositionAddFileRespDto;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author ： 手工接入方法
 * @version 1.0
 * @since 2022/5/28 15:32
 */
@Service
public class NbOrgPosition {
    /**
     * code:collectionRemoveDuplicateData
     * name:M去重职务所属对象（特殊方法）
     * desc:undefined
     **/
    @Trace(operationName = "M去重职务所属对象（特殊方法）")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    public CheckRemovalObjsRespDto checkRemovalObjs(CheckRemovalObjsReqDto reqDto) {
        // TODO ruizhe skai dong ; 2022/6/30 下午11:51:08
        return new CheckRemovalObjsRespDto();
    }

    /**
     * code:dataAucClassification
     * name:M1执行分类部门职务新增与存档（特殊方法）
     * desc:undefined
     * gen by moon at 8/10/2022, 3:12:29 AM
     **/
    @Trace(operationName = "M1执行分类部门职务新增与存档（特殊方法）")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    public ImplementClassDeptPositionAddFileRespDto implementClassDeptPositionAddFile(ImplementClassDeptPositionAddFileReqDto reqDto) {
        ImplementClassDeptPositionAddFileRespDto retData = new ImplementClassDeptPositionAddFileRespDto();
        List<AddDeptPositionDto> addDeptPositionList = new ArrayList<>();
        List<String> fileDeptPosition = new ArrayList<>();
        Map<String, OrgInductionRecordDto> inducIndex = new HashMap<>();
        Map<String, OrgDeptPositionDto> orgIndex = new HashMap<>();
        for (OrgInductionRecordDto oneInduc : reqDto.getOrgInductionRecordList()) {
            inducIndex.put(oneInduc.getEntityId() + oneInduc.getPositionId(), oneInduc);
        }
        for (OrgDeptPositionDto oneDept : reqDto.getOrgDeptPositionList()) {
            orgIndex.put(oneDept.getOrgEntityId() + oneDept.getPositionId(), oneDept);
        }
        for (OrgInductionRecordDto oneInduc : reqDto.getOrgInductionRecordList()) {
            if (!inducIndex.containsKey(oneInduc.getEntityId() + oneInduc.getPositionId())
                    || orgIndex.containsKey(oneInduc.getEntityId() + oneInduc.getPositionId())) {
                AddDeptPositionDto elm = new AddDeptPositionDto();
                elm.setEntityId(oneInduc.getEntityId());
                elm.setPositionId(oneInduc.getPositionId());
                addDeptPositionList.add(elm);
            }
        }

        for (OrgDeptPositionDto oneDept : reqDto.getOrgDeptPositionList()) {
            if (!inducIndex.containsKey(oneDept.getOrgEntityId() + oneDept.getPositionId())
                    || orgIndex.containsKey(oneDept.getOrgEntityId() + oneDept.getPositionId())) {
                fileDeptPosition.add(oneDept.getOrgPositionRelationshipId());
            }
        }
        retData.setAddDeptPositionList(addDeptPositionList);
        retData.setFileDeptPosition(fileDeptPosition);
        return retData;
    }
    //手工接入方法
}
